package com.ultrasoft.farmasoft.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Rolprovider;

@Repository(value = "rolProviderDao")
@Transactional(readOnly = false)
public class RolProviderDaoImpl implements RolProviderDao {

	private EntityManager em = null;
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	} 
	public List<Rolprovider> getListRolProvider() {
		TypedQuery<Rolprovider> rolProvider = em.createNamedQuery("Rolprovider.findAll", Rolprovider.class);
    	return rolProvider.getResultList();
	}

	public Rolprovider findByRolProviderId(Integer rolProviderId) {
		Rolprovider res=null;
		try {
			res=em.find(Rolprovider.class,rolProviderId);
		} catch (Exception e) {
			// TODO: handle exception
		}
    	return res;
	}
	public void update(Rolprovider rolProvider) {
		em.merge(rolProvider);
	}
	public void remove(Rolprovider rolProvider) {
		em.remove(em.getReference(Rolprovider.class,rolProvider.getRolProviderId()));
	}
	public void add(Rolprovider rolProvider) {
		em.persist(rolProvider);
	}

}
